<template>
    <el-container class="mev-div-border" style="color: white">
        <el-header style="height: 15px;">
            <el-row>
                <el-col :span="8" style="text-align: left;">
                    GPS
                </el-col>
                <el-col :span="16" style="text-align: right;">
                    <i @click="close()" size="medium" class="el-icon-close"></i>
                </el-col>
            </el-row>
        </el-header>
        <el-main>
            <el-row>
                <el-col :span="8"> 采样<br />间隔 </el-col>
                <el-col :span="16" style="position: absolute;top: 10px;right: 0px">
                    <el-input size="mini" v-model="inputStep" type="number" @input="onInput()" placeholder="输入记录间隔(秒)"></el-input>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8"> 定位<br />服务 </el-col>
                <el-col :span="16" style="position: absolute;top: 10px;right: 0px">
                    <el-switch v-model="switchGPSValue" @change="switchServiceChanged" active-text="开启" inactive-text="关闭"> </el-switch>
                </el-col>
            </el-row>
            <el-divider></el-divider>

            <el-row>
                <el-col :span="8"> 显示<br />轨迹 </el-col>
                <el-col :span="16" style="position: absolute;top: 10px;right: 0px">
                    <el-switch v-model="switchShowTrackValue" @change="switchShowTrackChanged" active-text="开启" inactive-text="关闭"> </el-switch>
                </el-col>
            </el-row>
            <!--
            <el-divider></el-divider>
            <el-row>
                <el-col :span="12">
                    <el-button @click="importdata()" size="small" plain>导入轨迹</el-button>
                </el-col>
                <el-col :span="12">
                    <el-button @click="outputData()" size="small" plain>导出轨迹</el-button>
                </el-col>
                <el-col :span="12">
                    <el-button @click="removeOutputData()" size="small" plain>清除轨迹</el-button>
                </el-col>

            </el-row>
            -->
        </el-main>
    </el-container>
</template>

<script>
import GPSHandler from "../../plugins/mev/gps/gps_handler";

export default {
    name: "GPSComponent",
    data() {
        return {
            inputStep: "2",
            switchGPSValue: false,
            switchShowTrackValue: false
        };
    },
    beforeDestroy() {},

    mounted() {
        //this.gpshandler = new GPSHandler(window.cesiumViewer);
        this.switchGPSValue = GPSHandler.getInstance().getServiceStatus();
        this.switchShowTrackValue = GPSHandler.getInstance().getRecordGPSEnabled();
    },
    methods: {
        close: function() {
            if (this.$route.name !== "EmptyComponent") {
                this.$router.push({ name: "EmptyComponent" });
            }
            //GPSHandler.getInstance().clearData();
        },
        switchServiceChanged: function(b) {
            //JavaContext.changeGPSFlag(b);
            let sec = -1;
            if (b) sec = 1;
            let res = GPSHandler.getInstance().setServiceEnabled(sec);
            if (b) {
                this.$message(res ? "GPS服务已打开！" : "GPS服务打开失败！");
                this.switchGPSValue = res;
            } else {
                this.$message(res ? "GPS服务已关闭！" : "GPS服务关闭失败！");
                this.switchGPSValue = !res;
            }
        },
        //显示
        switchShowTrackChanged: function(b) {
            GPSHandler.getInstance().setRecordGPSEnabled(b, parseInt(this.inputStep));
        },
        // //记录
        // switchRecordTrackChanged: function(b) {
        //     GPSHandler.getInstance().setRecordGPSEnabled(b, parseInt(this.inputStep));
        // },
        importdata: function() {
            GPSHandler.getInstance().clearData();
            this.gpshandler.importGps();
            let that = this;
            GPSHandler.getGPSData = function(data) {
                that.$message(data);
            };
        },
        outputData: function() {
            let str = GPSHandler.outputGps();
            let text = "导出成功:";
            if (str.length < 1) {
                text = "导出失败!";
            } else {
                text += str;
            }
            this.$message(text);
        },
        removeOutputData: function() {
            GPSHandler.getInstance().clearData();
            GPSHandler.getInstance().RemoveOutputGps();
        }
    }
};
</script>

<style scoped>
.el-row {
    margin-top: 10px;
    vertical-align: middle;
}
.el-divider {
    background-color: #3e4246;
}
</style>
